﻿Public Class fTipoVendedor
    Dim daTipoVend As lbGlobalcom.dsTerceroTableAdapters.TER_TIPOVENDEDORTableAdapter
    Dim daEstVend As lbGlobalcom.dsGlobalTableAdapters.GLO_DATOSTABLASTableAdapter
    Dim daClave As lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
    Private Sub btncargaTipoVend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncargaTipoVend.Click
        Try
            If DsTercero.TER_TIPOVENDEDOR.GetChanges IsNot Nothing Then
                TER_TIPOVENDEDORBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios Pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    daTipoVend.Update(DsTercero.TER_TIPOVENDEDOR)
                End If
            End If
            daTipoVend.Fill(DsTercero.TER_TIPOVENDEDOR)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub fTipoVendedor_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If DsTercero.TER_TIPOVENDEDOR.GetChanges IsNot Nothing Then
                TER_TIPOVENDEDORBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios Pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    daTipoVend.Update(DsTercero.TER_TIPOVENDEDOR)
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub fTipoVendedor_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            daTipoVend = New lbGlobalcom.dsTerceroTableAdapters.TER_TIPOVENDEDORTableAdapter
            daEstVend = New lbGlobalcom.dsGlobalTableAdapters.GLO_DATOSTABLASTableAdapter
            daEstVend.FillByIdGrupo(DsGlobal.GLO_DATOSTABLAS, "es")
            daClave = New lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            TER_TIPOVENDEDORBindingSource.Remove(TER_TIPOVENDEDORBindingSource.Current)
            daTipoVend.Update(DsTercero.TER_TIPOVENDEDOR)
        End If
    End Sub

    Private Sub TER_TIPOVENDEDORDataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles TER_TIPOVENDEDORDataGridView.CellBeginEdit
        If e.ColumnIndex = 1 AndAlso TER_TIPOVENDEDORDataGridView.Rows(e.RowIndex).Cells(0).Value Is DBNull.Value Then
            Dim dt As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASDataTable
            dt = daClave.GetDataByIdClavePrimaria("TER_TIPOVENDEDOR")
            If dt.Count Then
                Dim dr As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASRow
                dr = dt.Rows(0)
                Dim Cons As lbGlobalcom.ConsecTablas = New lbGlobalcom.ConsecTablas(dr("TABLA"), dr("CAMPO"), dr("LONGITUD"))
                TER_TIPOVENDEDORDataGridView.Rows(e.RowIndex).Cells(0).Value = Cons.NumeroConsec
                Cons = Nothing
                TER_TIPOVENDEDORBindingSource.EndEdit()
                daTipoVend.Update(DsTercero.TER_TIPOVENDEDOR)
            End If
        End If
    End Sub

    Private Sub TER_TIPOVENDEDORDataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles TER_TIPOVENDEDORDataGridView.DataError
        MessageBox.Show(e.Exception.Message)
    End Sub

    Private Sub TER_TIPOVENDEDORDataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles TER_TIPOVENDEDORDataGridView.UserDeletedRow
        Try
            daTipoVend.Update(DsTercero.TER_TIPOVENDEDOR)
            MessageBox.Show("Se elimino registro con exito", "Elimina Registro", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub TER_TIPOVENDEDORDataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles TER_TIPOVENDEDORDataGridView.UserDeletingRow
        If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub

    Private Sub TER_TIPOVENDEDORBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TER_TIPOVENDEDORBindingNavigatorSaveItem.Click
        Try
            Validate()
            TER_TIPOVENDEDORBindingSource.EndEdit()
            daTipoVend.Update(DsTercero.TER_TIPOVENDEDOR)
            MessageBox.Show("Se salvarón registros con exito", "Salvar Registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub
End Class